/**
 * java多线程模式
 * @author andy.rong
 */

package com.myjavalab.thread;

public class ThreadInterrupt extends Thread{

	public ThreadInterrupt(String name){
		super(name);
	}
	
	public static void main(String[] args) {
		ThreadInterrupt in = new ThreadInterrupt("interrupt");
		in.start();
	}
	
	public void run() {
		System.out.println("isInterrupted :" + this.isInterrupted());
		System.out.println("interrupted status : " + Thread.interrupted() + " -- then clear interrupted status ");  
		this.interrupt();
		System.out.println("isInterrupted :" + this.isInterrupted());

		//interrupted()-- check interrupted status and clear interrupted status
		System.out.println("interrupted status : " + Thread.interrupted() + " -- then clear interrupted status ");  
		System.out.println("isInterrupted() :" + this.isInterrupted());
		
		this.interrupt();
		
		try {			
			System.out.println("before sleep isInterrupted() :" + isInterrupted());
			//check interrupted status, if true , throw InterruptedException
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();

		}
		System.out.println("after sleep isInterrupted() :" + this.isInterrupted());
	}
}
